/**
 * Copyright (C), 2020-2021
 * File Name: SysLogger.java
 * Encoding: UTF-8
 * Date: 2021年3月12日 下午4:32:44
 * History:
*/
package com.swak.frame.logger;

import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.event.Level;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;

public class SysLogger implements Logger {

	private String loggerName;

	private SysLogger(String loggerName) {
		this.loggerName = loggerName;
	}

	public static Logger getLogger(Class<?> clz) {
		return new SysLogger(clz.getName());
	}

	public static Logger getLogger(String loggerName) {
		return new SysLogger(loggerName);
	}

	@Override
	public String getName() {
		return loggerName;
	}

	@Override
	public void debug(String msg) {
		System.out.println("[" + loggerName + "] DEBUG: " + msg);
	}

	@Override
	public void info(String msg) {
		System.out.println("[" + loggerName + "] INFO: " + msg);
	}

	@Override
	public void warn(String msg) {
		System.out.println("[" + loggerName + "] WARN: " + msg);
	}

	@Override
	public void error(String msg) {
		System.err.println("[" + loggerName + "] ERROR: " + msg);
	}

	@Override
	public void error(String msg, Throwable t) {
		System.err.println("[" + loggerName + "] ERROR: " + msg);
		t.printStackTrace();
	}

	@Override
	public void error(String format, Object arg) {
		FormattingTuple ft = MessageFormatter.format(format, arg);
		System.err.println("[" + loggerName + "] ERROR: " + ft.getMessage());
	}

	@Override
	public void error(String format, Object arg1, Object arg2) {
		FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
		System.err.println("[" + loggerName + "] ERROR: " + ft.getMessage());
	}

	@Override
	public void error(String format, Object... arguments) {
		FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
		System.err.println("[" + loggerName + "] ERROR: " + ft.getMessage());
	}

	@Override
	public boolean isErrorEnabled(Marker marker) {
		return true;
	}

	@Override
	public void error(Marker marker, String msg) {
		error(msg);
	}

	@Override
	public void error(Marker marker, String format, Object arg) {
		error(format, arg);
	}

	@Override
	public void error(Marker marker, String format, Object arg1, Object arg2) {
		error(format, arg1, arg2);
	}

	@Override
	public void error(Marker marker, String format, Object... arguments) {
		error(format, arguments);
	}

	@Override
	public void error(Marker marker, String msg, Throwable t) {
		error(msg, t);
	}

	@Override
	public boolean isTraceEnabled() {
		return true;
	}

	@Override
	public void trace(String msg) {
		print(Level.TRACE, msg);
	}

	@Override
	public void trace(String format, Object arg) {
		print(Level.TRACE, format, arg);
	}

	@Override
	public void trace(String format, Object arg1, Object arg2) {
		print(Level.TRACE, format, arg1, arg2);
	}

	@Override
	public void trace(String format, Object... arguments) {
		print(Level.TRACE, format, arguments);
	}

	@Override
	public void trace(String msg, Throwable t) {
		print(Level.TRACE, msg, t);
	}

	@Override
	public boolean isTraceEnabled(Marker marker) {
		return true;
	}

	@Override
	public void trace(Marker marker, String msg) {
		trace(msg);
	}

	@Override
	public void trace(Marker marker, String format, Object arg) {
		trace(format, arg);
	}

	@Override
	public void trace(Marker marker, String format, Object arg1, Object arg2) {
		trace(format, arg1, arg2);
	}

	@Override
	public void trace(Marker marker, String format, Object... argArray) {
		trace(format, argArray);

	}

	@Override
	public void trace(Marker marker, String msg, Throwable t) {
		trace(msg, t);
	}

	@Override
	public boolean isDebugEnabled() {
		return true;
	}

	@Override
	public void debug(String format, Object arg) {
		print(Level.DEBUG, format, arg);
	}

	@Override
	public void debug(String format, Object arg1, Object arg2) {
		print(Level.DEBUG, format, arg1, arg2);
	}

	@Override
	public void debug(String format, Object... arguments) {
		print(Level.DEBUG, format, arguments);
	}

	@Override
	public void debug(String msg, Throwable t) {
		print(Level.DEBUG, msg, t);
	}

	@Override
	public boolean isDebugEnabled(Marker marker) {
		return true;
	}

	@Override
	public void debug(Marker marker, String msg) {
		debug(msg);
	}

	@Override
	public void debug(Marker marker, String format, Object arg) {
		debug(format, arg);
	}

	@Override
	public void debug(Marker marker, String format, Object arg1, Object arg2) {
		debug(format, arg1, arg2);
	}

	@Override
	public void debug(Marker marker, String format, Object... arguments) {
		debug(format, arguments);
	}

	@Override
	public void debug(Marker marker, String msg, Throwable t) {
		debug(msg, t);
	}

	@Override
	public boolean isInfoEnabled() {
		return true;
	}

	@Override
	public void info(String format, Object arg) {
		print(Level.INFO, format, arg);
	}

	@Override
	public void info(String format, Object arg1, Object arg2) {
		print(Level.INFO, format, arg1, arg2);
	}

	@Override
	public void info(String format, Object... arguments) {
		print(Level.INFO, format, arguments);
	}

	@Override
	public void info(String msg, Throwable t) {
		print(Level.INFO, msg, t);
	}

	@Override
	public boolean isInfoEnabled(Marker marker) {
		return true;
	}

	@Override
	public void info(Marker marker, String msg) {
		print(Level.INFO, msg);
	}

	@Override
	public void info(Marker marker, String format, Object arg) {
		print(Level.INFO, format, arg);
	}

	@Override
	public void info(Marker marker, String format, Object arg1, Object arg2) {
		print(Level.INFO, format, arg1, arg2);
	}

	@Override
	public void info(Marker marker, String format, Object... arguments) {
		print(Level.INFO, format, arguments);
	}

	@Override
	public void info(Marker marker, String msg, Throwable t) {
		info(msg, t);

	}

	@Override
	public boolean isWarnEnabled() {
		return true;
	}

	@Override
	public void warn(String format, Object arg) {
		print(Level.WARN, format, arg);
	}

	@Override
	public void warn(String format, Object... arguments) {
		print(Level.WARN, format, arguments);
	}

	@Override
	public void warn(String format, Object arg1, Object arg2) {
		print(Level.WARN, format, arg1, arg2);

	}

	@Override
	public void warn(String msg, Throwable t) {
		print(Level.WARN, msg, t);
	}

	@Override
	public boolean isWarnEnabled(Marker marker) {
		return true;
	}

	@Override
	public void warn(Marker marker, String msg) {
		warn(msg);
	}

	@Override
	public void warn(Marker marker, String format, Object arg) {
		warn(format, arg);
	}

	@Override
	public void warn(Marker marker, String format, Object arg1, Object arg2) {
		warn(format, arg1, arg2);
	}

	@Override
	public void warn(Marker marker, String format, Object... arguments) {
		warn(format, arguments);
	}

	@Override
	public void warn(Marker marker, String msg, Throwable t) {
		warn(msg, t);
	}

	@Override
	public boolean isErrorEnabled() {
		return true;
	}

	private void print(Level level, String msg) {
		System.out.println("[" + loggerName + "] " + level.toString() + ": " + msg);
	}

	private void print(Level level, String format, Object arg) {
		FormattingTuple ft = MessageFormatter.format(format, arg);
		System.out.println("[" + loggerName + "]  " + level.toString() + ": " + ft.getMessage());
	}

	private void print(Level level, String format, Object arg1, Object arg2) {
		FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
		System.out.println("[" + loggerName + "] " + level.toString() + ": " + ft.getMessage());
	}

	private void print(Level level, String format, Object... arguments) {
		FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
		System.out.println("[" + loggerName + "] " + level.toString() + ": " + ft.getMessage());
	}

	private void print(Level level, String msg, Throwable t) {
		System.out.println("[" + loggerName + "] " + level.toString() + ": " + msg);
		t.printStackTrace();
	}

}
